/**
 * 
 */
$(function(){
	$("#save").click(function(){
		var name=$("#name").val();//20
		var udoc=$("#udoc").val();//20
		var sex = $('input[name="sex"]:checked ').val(); 
		var uage=$("#uage").val();//number 3
		var uphone=$("#uphone").val();//number 20
		var umail=$("#umail").val();//200
		var ufrom=$("#ufrom").val();//200
		var uaddr=$("#uaddr").val();//200
		var uname=$("#uname").val();//20
		var upwd=$("#upwd").val();
		var urepwd=$("#urepwd").val();
		var uol=$("#uol").val();
		var ucash=$("#ucash").val(); //20,2
		var paypwd=$("#paypwd").val();
		var repaypwd=$("#repaypwd").val();
		if(!check()){
			
		}else{
			$.getJSON(
				"add_user",
				{
					"name":name,
					"udoc":udoc,
					"sex":sex,
					"uage":uage,
					"uphone":uphone,
					"umail":umail,
					"ufrom":ufrom,
					"uaddr":uaddr,
					"uname":uname,
					"upwd":upwd,
					"uol":uol,
					"ucash":ucash,
					"paypwd":paypwd
				},
				function(data){
					if(data.status==0){
						var num=data.num;
						alert("开户成功！您的卡号为"+num+",已存入"+data.cash+"元。");
					}else{
						alert(data.info);
					}
				});
		}
	});
})

function check(){
	var name=$("#name").val();
	var udoc=$("#udoc").val();
	var sex = $('input[name="sex"]:checked ').val(); 
	var uage=$("#uage").val();
	var uphone=$("#uphone").val();
	var umail=$("#umail").val();
	var ufrom=$("#ufrom").val();
	var uaddr=$("#uaddr").val();
	var uname=$("#uname").val();
	var upwd=$("#upwd").val();
	var urepwd=$("#urepwd").val();
	var uol=$("#uol").val();
	var ucash=$("#ucash").val(); //20,2
	var paypwd=$("#paypwd").val();
	var repaypwd=$("#repaypwd").val();
	
	if(upwd==""||upwd!=urepwd){
		
		alert("密码错误或两次登录密码不一致")
		return false;
	}
	
	if(upwd==paypwd){
		alert("登录密码不能与支付密码一致");
		return false;
	}
	
	if(paypwd!=repaypwd){
		alert("密码错误或两次支付密码不一致");
		return false;
	}
	
	if(len(name)>20||name==""){
		alert("用户名不能为空或长度过长！");
		return false;
	}
	
	/*if(!checkIDCard(udoc)||udoc==""){
		alert("身份证号错误！");
		return false;
	}*/
	
	if(!checkNum(uage)||uage==""||uage.length>3){
		alert("年龄输入错误！");
		return false;
	}
	
	if(!checkNum(uphone)||uphone.length!=11){
		alert("手机号不正确");
		return false;
	}
	
	/*if(!checkMail(umail)||umail==""){
		alert("邮箱不正确!");
		return false;
	}*/
	
	if(len(ufrom)>200||ufrom==""){
		alert("籍贯错误！");
		return false;
	}
	
	if(len(uaddr)>200||uaddr==""){
		alert("住址错误!");
		return false;
	}
	
	if(len(uname)>20||uname==""){
		alert("用户名错误");
		return false
	}
	
	/*if(!checkCash(ucash)||ucash==""){
		alert("现金格式错误！")
		return false;
	}*/
	return true;
}